Skip to content

fix(renderer): sanitize embedded newlines in Output.add_line - #447

Merged
sudo-tee merged 1 commit into
sudo-tee:mainfrom
phanen:fix/santinize-newlines
Jul 7, 2026
Merged

fix(renderer): sanitize embedded newlines in Output.add_line#447
sudo-tee merged 1 commit into
sudo-tee:mainfrom
phanen:fix/santinize-newlines

Conversation

@phanen

@phanen phanen commented Jul 5, 2026

Copy link
Copy Markdown
Contributor
Problem: when the LLM emits question options (or any other
server-supplied text) whose label or description contains a literal
newline, format_options inserts the raw string as a single line in
the formatted output. nvim_buf_set_lines then rejects the line
with 'replacement string item contains newlines' and the whole
flush errors out, dropping the part from the rendered buffer and
leaving an apparently-broken dialog (only the title text visible).

Solution: replace any embedded \r\n, \n, or \r with a single
space at the Output layer. This is the natural defensive boundary:
every line that flows to nvim_buf_set_lines goes through add_line
or add_lines, so sanitizing there covers every renderer call site
(question options, permission titles, MCP tool output, etc.) at
once without scattering special-case handling.

To reproduce, maybe just ask opencode to:

Use question tool call with newline in string param to test if it work well

@phanen
phanen marked this pull request as draft July 5, 2026 16:03
@phanen

phanen commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Not sure if there any best way to fix. I originally notice question dialog won't show up if some error happened before that.

Maybe a schema error event in opencode side will produce another bug, I haven't confirm.

Comment thread lua/opencode/ui/output.lua Outdated
@phanen
phanen force-pushed the fix/santinize-newlines branch 2 times, most recently from 46d0592 to d445197 Compare July 6, 2026 06:55
@phanen
phanen force-pushed the fix/santinize-newlines branch from d445197 to 833e09d Compare July 6, 2026 14:14
@phanen
phanen marked this pull request as ready for review July 7, 2026 05:16
@phanen

phanen commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

The prompt to test: Insert newline characters into the string parameters of the question tool call and run a test, aggressively testing as many cases as possible.

@sudo-tee

sudo-tee commented Jul 7, 2026

Copy link
Copy Markdown
Owner

The fix make sense to me.

Thanks for the PR

@sudo-tee
sudo-tee merged commit 49da835 into sudo-tee:main Jul 7, 2026
5 checks passed
@phanen
phanen deleted the fix/santinize-newlines branch July 13, 2026 15:06
disrupted pushed a commit to disrupted/opencode-native.nvim that referenced this pull request Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants